<include file="../header" />
<body class="J_scroll_fixed">
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&key=FO5BZ-2AC2G-ACAQV-I5BD3-YX65K-76BUB"></script>
    <script src="http://open.map.qq.com/apifiles/v1.0/app.js?v=1.0.131203.1" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            

                $('input.checkStaff').click(function () {

                    var staffNumber = $('input[name=staffNumber]').val();
                    var companyId = $('input[name=id]').val();

                    $.ajax({
                        type: "post",
                        url: "{:U('company/checkStaff')}",
                        data: {staffNumber: staffNumber, companyId: companyId},
                        dataType: "json",
                        success: function (data) {

                            if (data['errCode'] === 500) {
                                layer.msg('请添加该员工信息!');
                                $('#checkStaffDiv').show();
                                
                                $('input[name=staffName]').val("");
                                $('input[name=mobile]').val("");
                                
                                $('input[name=staffName]').attr("readOnly",false);
                                $('input[name=staffNumber]').attr("readOnly",false);
                                $('input[name=mobile]').attr("readOnly",false);
                                $('select[name=gender]').removeAttr("disabled"); 
           
                            } else {
                                layer.msg('该员工编号存在,请核对员工信息!');
                                $('#checkStaffDiv').show();
                                
                                $('input[name=staffName]').val(data['staffName']);
                                $('input[name=mobile]').val(data['mobile']);
                                $('select[name=gender]').val(data['gender']);
                                                                                             
                                $('input[name=staffName]').attr("readOnly",true);
                                $('input[name=staffNumber]').attr("readOnly",false);
                                $('input[name=mobile]').attr("readOnly",true);
                                $('select[name=gender]').attr("disabled","disabled"); 

                            }
                        },
                        error: function () {
                            layer.msg('请求出错！！');
                        }
                    });
                });
                $('button.train').click(function () {
                    var staffNumber= $('input[name=staffNumber]').val();
                    var staffName=$('input[name=staffName]').val();
                    var mobile=$('input[name=mobile]').val();
                    var gender=$('select[name=gender]').val();
                    if (staffNumber == '' || staffNumber == null) {
                        layer.msg('员工编号不能为空!');
                        return false;
                    } 
                     if (staffName == '' || staffName == null) {
                        layer.msg('员工名称不能为空!');
                        return false;
                    }
                    //验证手机号格式
                    if(!mobileValidate($.trim(mobile))) {             
                        return false;
                    }
                     if (gender == '' || gender == null) {
                        layer.msg('性别不能为空!');
                        return false;
                    }else {
                        $("#trainForm").submit();
                    }
                });

            });
    </script>
    <div class="wrap jj">
        <div class="common-form">
            <form id="trainForm" method="post" class="form-horizontal J_ajaxForm" action="{:U('company/trainPost')}">

                <input type="hidden" name='id' value='{$company.company_id}'/>
                <fieldset>
                    <div class="control-group">
                        <label class="control-label">员工号：</label>
                        <div class="controls">
                            <input id='staffNumber' type="text" class="input" name="staffNumber" value="" placeholder="请输入员工号并验证">
                            <input type="button" class="checkStaff btn" id="{$companyId}" value="验证" />
                        </div>                                               
                    </div>
                    <div  id="checkStaffDiv" style="display: none">
                        <div class="control-group">
                            <label class="control-label">公司名称:</label>
                            <div class="controls">
                                    <input type="text" class="input" name="companyName" value="{$company.company_name}" readOnly='true'>    
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">员工名称：</label>
                            <div class="controls">
                                    <input id='staffName' type="text" class="input" name="staffName" value="" readOnly='true'>    
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">性别:</label>
                            <div class="controls">
                                {:getEnumSelectWidget($gender,'gender')}
                            </div>
			</div>
                            <div class="control-group">
                                <label class="control-label">手机号：</label>
                                <div class="controls">
                                    <input id='mobile' type="text" class="input" name="mobile" value="" readOnly='true'>    
                                </div>
                            </div>
                        </div>
                </fieldset>
                <div class="form-actions">
                    <button  class="train btn btn-primary" id="send">我要锻炼</button>
                </div>
            </form>
        </div>
    </div>    
    <script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>